package com.shujiaotong.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shujiaotong.common.R;
import com.shujiaotong.pojo.*;
import com.shujiaotong.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-20
 */
@RestController
@RequestMapping("/comment")
@Slf4j
public class CommentController {
    @Autowired
    private ICommentService commentService;
//    getCommentsByShopId
    @GetMapping("getCommentsByShopId/{id}")
    public R getCommentsByShopId(@PathVariable Long id){
        LambdaQueryWrapper<Comment> qw = new LambdaQueryWrapper<>();
        qw.eq(Comment::getShopId,id);
        return R.success(commentService.list(qw));
    }

    @PostMapping("/submitComment")
    public R submitComment(@RequestBody Comment comment){
        comment.setCreateTime(LocalDate.now());
        return commentService.save(comment)?R.success("评论成功"):R.error("评论失败");
    }

}
